﻿MPT.addAction("clm_visiter", function(_elm) {

    var shift_l_jQ = $('.e_shift_l', _elm);
    var shift_r_jQ = $('.e_shift_r', _elm);
    var more_jQ = $('.e_more', _elm);
    var body_jQ = $('.e_body', _elm);
    var count_jQ = $('.e_count', _elm);
    var data_jQ = $('.e_data', _elm);
    var no_data_jQ = $('.e_no_data', _elm);
    var now_id = null;

    var userID = Util.GetHashParam();

    if(userID){
        now_ID = userID;

        more_jQ.hide();
    }else{
        now_ID = MPT.Config["session"]["userid"];
    }

    var data = { "pageNo": 1, "type": 0, "pageSize": 12, "targetId": now_ID };

    var initialize = function() {
        more_jQ.click(function() { window.location.hash = MPT.Config["hash"]["visit"] });

        Backend.findVisitRecordsSimple(data, function(_resp) {
            if (Backend.pageBeanValidate(_resp)) {
                var results = _resp.results;
                var count = _resp.totalRecoreds;
                var html = [];

                count_jQ.html(count);

                no_data_jQ.hide();
                data_jQ.show();

                $.each(results, function(_i, _r) {
                    var visitorId = _r.visitorId;
                    var nickName = _r.nickName;
                    var truncName = Util.truncName(_r.nickName, 4);
                    var avatarPath = Util.avatarPath(_r.visitorId);
                    var spacePath = Util.spacePath(_r.visitorId);

                    html.push('<li>');
                    html.push('<h2 class="face"><a href=' + spacePath + ' title="' + nickName + '">');
                    html.push('<img src="' + avatarPath + '" alt="' + nickName + '"></a></h2>');
                    html.push('<p class="name" title="' + nickName + '">' + truncName + '</p>');
                    html.push('</li>');
                });

                body_jQ.html(html.join(''));

                var page_count = Math.ceil(results.length / 4);
                (new Paginate).createPageShift(shift_r_jQ, shift_l_jQ, body_jQ, 260, page_count, "fast");

            } else {
                no_data_jQ.html('还没有访问记录');
            }
        }, function() {
            no_data_jQ.html('数据加载错误');
        });
    }

    initialize();
});